package cn.gjculture.shopping.api.controller;

import cn.gjculture.shopping.api.entity.Notice;
import cn.gjculture.shopping.api.entity.PageInfo;
import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/notice")
public class NoticeController {

    @Autowired
    NoticeService noticeService;

    @PostMapping
    public Return save(Notice notice, Return ret){
        int i=noticeService.save(notice);
        if (i>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }

    @GetMapping(value = "/publish")
    public Return<List<Notice>> queryPublish(PageInfo info,Return<List<Notice>> ret){
        List<Notice> notices=noticeService.queryPublish();
        ret.setData(notices);
        return ret;

    }

    @GetMapping(value = "/recommend")
    public Return<List<Notice>> queryRecommend(PageInfo info,Return<List<Notice>> ret){
        List<Notice> notices=noticeService.queryRecommend();
        ret.setData(notices);
        return ret;
    }
}
